package com.day15_Stream;

import java.util.ArrayList;

/**
 * @ClassName: Demo01
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/3/24-23:53
 * @Version 1.0
 */
public class Demo01 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("孙悟饭");
        list.add("孙悟空");
        list.add("龟仙人");
        list.add("克林");
        list.add("天津饭");
        list.add("孙悟天");
        list.add("孙悟天-爷爷");
        // 把集合中以孙开头的元素存储到一个新的集合
        ArrayList<String> sun_list = new ArrayList<>();
        for (String i: list)  {
            if (i.startsWith("孙")) {
                sun_list.add(i);
            }
        }
        System.out.println(sun_list);
        // 把孙开头的集合中长度为3的元素存储到新集合
        ArrayList<String> newsun_list = new ArrayList<>();
        for (String i: sun_list) {
            if(i.length() == 3) {
                newsun_list.add(i);
            }
        }
        System.out.println(newsun_list);
    }
}
